<template>
<div class="wrapper" ref="wrapper">
  <div class="content">
    <slot></slot>
  </div>
</div>
</template>

<script>
import BScroll from 'better-scroll'

export default {
  name: 'Scroll',
  data() {
    return {
      scroll: null,
    }
  },
  //等Home里面给我传入一个属性，当传入2或3时，启动监听----占用大量性能
  props: {
    probeType: {
      type: Number,
      default: 0,
    },
    pullUpLoad: {
      type: Boolean,
      default: false,
    },
  },
  mounted() {
    //1.创建scroll对象
    this.scroll = new BScroll(this.$refs.wrapper, {
      click: true,
      probeType: this.probeType,
      //让别人传入pullUpLoad，是否要上拉监听
      pullUpLoad: this.pullUpLoad,
    })
    //2.监听滚动位置
    this.scroll.on('scroll', (position) => {
      this.$emit('scroll', position)
    })
    //3.监听上拉事件---上拉加载更多
    this.scroll.on('pullingUp', () => {
      this.$emit('pullingUp')
    })
  },
  methods: {
    refresh() {
      //console.log('我是防抖测试')
      this.scroll && this.scroll.refresh()
    },
  },
}
</script>
